package com.bridgeQQ.client.util
{
	import mx.formatters.DateFormatter;

	public class DateUtil
	{
		private static var formatter:DateFormatter = new DateFormatter();
		
		/**
		 * 按照指定的格式，格式化事前，如果 skipToday为true，并且时间是当天，则只显示hour以后的时间
		 * @param date
		 * @param formatString
		 * @param skipToday
		 * @return 
		 * 
		 */		
		public static function format(date:Date, formatString:String, skipToday:Boolean = true):String
		{	
			if(skipToday)
			{
				var today:int = new Date().time / (1000 * 60 * 60 * 24);
				var dateDay:int = date.time / (1000 * 60 * 60 * 24);
				if(today == dateDay)
				{
					var end:int = formatString.search(/[YMDE]/);
					var start:int = formatString.search(/[AJHKLNS]/);
					end = start > end ? int.MAX_VALUE : end - 1; 
					formatString = formatString.substring(start, end);
				}	
			}
			formatter.formatString = formatString;
			var result:String = formatter.format(date);
			return result;
		}
	}
}